package lifeOfAFish;
import lifeOfAFish.fishModels.amago.Amago;
import lifeOfAFish.fishModels.amemasu.Amemasu;
import lifeOfAFish.fishModels.redBetta.RedBetta;
import lifeOfAFish.particleSystem.ParticleSystem;
import lifeOfAFish.plantModels.corals.magnificient.Magnificient;
import lifeOfAFish.plantModels.corals.sebea.Sebea;
import lifeOfAFish.plantModels.corals.tipped.Tipped;
import lifeOfAFish.scenegraph.sgGlobals;
import lifeOfAFish.scenegraph.sgMaterial;
import lifeOfAFish.scenegraph.sgTransform;
import lifeOfAFish.scenegraph.geom.*;
import lifeOfAFish.scenegraph.*;
import lifeOfAFish.splines.*;

/**
 * Class FishTank
 */
public class FishTank extends Entity{

	//
	// Fields
	//

	// Objects contained in the aquarium //
	private AnglerFish m_anglerFish;
	private Shark m_shark;
	private Plant m_plant;
	private Amago m_amago;
	private Amago m_amago2;
	private Amago m_amago3;
	private Amemasu m_amemasu;
	private Amemasu m_amemasu2;
	private Amemasu m_amemasu3;
	private Amemasu m_amemasu4;
	
	private RedBetta m_redBetta;
	private Magnificient m_magnificient;
	private Sebea m_sebea;
	private Tipped m_tipped;
	
	private AquariumFloor m_af;
	private WaterSurface m_waterSurface;
	
	ParticleSystem m_particleSystem;
	private static final int NumBubbles = 3;
	Bubbles[] m_bubbles = new Bubbles[NumBubbles];
	
	///////////////////////////////////////


//	private Light lights;

	//
	// Constructors
	//
	public FishTank () 
	{ 
		m_af = new AquariumFloor();
		
		m_shark = new Shark();
		m_anglerFish = new AnglerFish();
		m_plant = new Plant();
		
		// Add some plants
		m_magnificient = new Magnificient();
		m_sebea = new Sebea();
		m_tipped = new Tipped();
		
		// Add some fish
		m_amago = new Amago();
		m_amago2 = new Amago();
		m_amago3 = new Amago();
		m_amemasu = new Amemasu();
		m_amemasu2 = new Amemasu();
		m_amemasu3 = new Amemasu();
		m_amemasu4 = new Amemasu();
		m_redBetta = new RedBetta();
		
		// Instantiate Particle System
		m_particleSystem = new ParticleSystem();
		m_particleSystem.init(sgGlobals.gl);
		
		for(int c = 0; c < NumBubbles; c++){
			m_bubbles[c] = new Bubbles();
			m_bubbles[c].init();
			m_bubbles[c].setHeight(1.0f);
			m_node.addChild(m_bubbles[c].getNode());
		}
		m_bubbles[0].setOrigin(new sgVec3(2.0f, -0.5f, -1.5f));
		m_bubbles[1].setOrigin(new sgVec3(1.0f, 0.0f, -0.6f));
		m_bubbles[2].setOrigin(new sgVec3(3.5f, 0.0f, -0.5f));
		
		
		// create a cube to (temporarily) represent our fishtank
		sgMaterial mat1 = new sgMaterial();
		mat1.setAmbient(0.7f, 0.7f, 1.0f, 0.3f);
		mat1.setDiffuse(0.85f, 0.85f, 1.0f, 0.3f);
		mat1.setSpecular(1.0f, 1.0f, 1.0f, 0.3f);
		
//		float[] origin = {0.0f, 0.0f, 0.0f};
//		sgGeomCuboid cube = new sgGeomCuboid(origin, 2.0f, 1.2f, 3.5f);
//		cube.setName("FishTank_cube");
//		cube.setMaterial(mat1);
//		cube.setOpaque(false);
//		
//		m_node.addChild(cube);
		boolean opaque = false;
		float width = 3.5f, height = 1.2f, depth = 2.0f;
		sgGeomRectYZ westWall = new sgGeomRectYZ(0.0f, height, 0.0f, depth);
		sgTransform wwTrans = new sgTransform(); wwTrans.translate(0.0f, 0.0f, -depth);
		westWall.setMaterial(mat1);
		westWall.setOpaque(opaque);
		wwTrans.addChild(westWall);
		m_node.addChild(wwTrans);
		
		sgGeomRectYZ eastWall = new sgGeomRectYZ(0.0f, height, 0.0f, depth);
		sgTransform ewTrans = new sgTransform(); ewTrans.translate(width, 0.0f, -depth);
		eastWall.setMaterial(mat1); 
		eastWall.setOpaque(opaque); 
		ewTrans.addChild(eastWall);
		m_node.addChild(ewTrans);
		
		sgGeomRectXY southWall = new sgGeomRectXY(0.0f, width-0.000001f, 0.0f, height);
		southWall.setMaterial(mat1);
		southWall.setOpaque(opaque);
		m_node.addChild(southWall);
		
		sgGeomRectXY northWall = new sgGeomRectXY(0.0f, width-0.000001f, 0.0f, height);
		sgTransform nwTrans = new sgTransform(); nwTrans.translate(0.0f, 0.0f, -depth);
		nwTrans.addChild(northWall);
		northWall.setOpaque(opaque);
		northWall.setMaterial(mat1);
		m_node.addChild(nwTrans);
		
		// Add Magnificient
		sgTransform magnificientTransform = new sgTransform();
		magnificientTransform.translate(1.0f, 0.23f, -0.5f);
		m_node.addChild(magnificientTransform);
		
		magnificientTransform.addChild(m_magnificient.getNode());
		m_magnificient.init();
		
		// Add Sebea
		sgTransform sebeaTransform = new sgTransform();
		sebeaTransform.translate(2.0f, 0.23f, -1.5f);
		m_node.addChild(sebeaTransform);
		
		sebeaTransform.addChild(m_sebea.getNode());
		m_sebea.init();
		
		// Add Tipped
		sgTransform tippedTransform = new sgTransform();
		tippedTransform.translate(0.7f, 0.25f, -1.3f);
		m_node.addChild(tippedTransform);
		
		tippedTransform.addChild(m_tipped.getNode());
		m_tipped.init();
		
		// Add Amago
		sgTransform amagoTransform = new sgTransform();
		amagoTransform.translate(1.0f, 0.5f, -0.5f);
		m_node.addChild(amagoTransform);
		
		amagoTransform.addChild(m_amago.getNode());
		m_amago.move = true;
		m_amago.init();
		
		// Add Amago2
		sgTransform amago2Transform = new sgTransform();
		amago2Transform.translate(0.6f, 1.0f, -0.7f);
		m_node.addChild(amago2Transform);
		
		amago2Transform.addChild(m_amago2.getNode());
		m_amago2.init();
		
		// Add Amago3
		sgTransform amago3Transform = new sgTransform();
		amago3Transform.translate(2.4f, 1.0f, -1.6f);
		m_node.addChild(amago3Transform);
		
		amago3Transform.addChild(m_amago3.getNode());
		m_amago3.move=true;
		m_amago3.init();
		
		
		// Add Amemasu
		sgTransform amemasuTransform = new sgTransform();
		amemasuTransform.translate(1.2f, 0.7f, -0.35f);
		m_node.addChild(amemasuTransform);
		
		amemasuTransform.addChild(m_amemasu.getNode());
		m_amemasu.init();
		
		// Add Amemasu2
		sgTransform amemasu2Transform = new sgTransform();
		amemasu2Transform.translate(2.6f, 0.7f, -1.35f);
		m_node.addChild(amemasu2Transform);
		
		amemasu2Transform.addChild(m_amemasu2.getNode());
		m_amemasu2.move=true;
		m_amemasu2.init();
		
		// Add Amemasu3
		sgTransform amemasu3Transform = new sgTransform();
		amemasu3Transform.translate(0.4f, 0.9f, -1.0f);
		m_node.addChild(amemasu3Transform);
		
		amemasu3Transform.addChild(m_amemasu3.getNode());
		m_amemasu3.move=true;
		m_amemasu3.init();
		
		// Add Amemasu4
		sgTransform amemasu4Transform = new sgTransform();
		amemasu4Transform.translate(1.3f, 0.7f, -0.65f);
		m_node.addChild(amemasu4Transform);
		
		amemasu4Transform.addChild(m_amemasu4.getNode());
		m_amemasu4.init();
		
		//Add Aquarium Floor
		sgTransform floorTransform = new sgTransform();
		floorTransform.translate(0.0f, 0.0f, 0.0f);
		m_node.addChild(floorTransform);
		floorTransform.addChild(m_af);
		m_node.addChild(floorTransform);
		m_af.init();
		m_af.loadTexture("models/textures/sand.jpg");
		
		
		// Add RedBetta
		sgTransform redBettaTransform = new sgTransform();
		redBettaTransform.translate(2.0f, 0.6f, -0.7f);
		m_node.addChild(redBettaTransform);
		
		redBettaTransform.addChild(m_redBetta.getNode());
		m_redBetta.init();
		
		m_waterSurface = new WaterSurface();
		m_waterSurface.init();
		m_node.addChild(m_waterSurface.getNode());
//		
		
	}
	
	public void fishCam(sgCamera cam){
		
		System.out.println(m_redBetta.getEye().getGlobalCoords());
		
		cam.lookAt(sgVec3.subtract(m_redBetta.getEye().getGlobalCoords(), new sgVec3(0.05f, 0.15f, 0.0f)), 
				m_redBetta.getAt().getGlobalCoords(),
				new sgVec3(0.0f, 1.0f, 0.0f));
	}


	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void init() {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void update() {
	
		m_magnificient.update();
		m_sebea.update();
		m_tipped.update();
		m_amago.update();
		m_amago2.update();
		m_amago3.update();
		m_amemasu.update();
		m_amemasu2.update();
		m_amemasu3.update();
		m_amemasu4.update();
		
		m_redBetta.update();
		
		for(int c = 0; c < NumBubbles; c++){
			m_bubbles[c].update();
		}
	};

	//
	// Methods
	//


	//
	// Accessor methods
	//

	/**
	 * Set the value of lights
	 * @param newVar the new value of lights
	 */
//	public void SetLights ( Light newVar ) {
//		lights = newVar;
//	}
//
//	/**
//	 * Get the value of lights
//	 * @return the value of lights
//	 */
//	public Light GetLights ( ) {
//		return lights;
//	}

	//
	// Other methods
	//


}
